SwitchGroupEvent = RegisterEvents{
    "Selected"
}
SwitchGroup = {
    props = {
        allowMultiSelect = false,
        _allowSwitchOff = false,
        _selectedSwitchIndex = 0
    },
    gets = {
        selectedSwitchIndex = function(self)
            return self._selectedSwitchIndex
        end,
        allowSwitchOff = function(self)
            return self._allowSwitchOff
        end
    },
    sets = {
        selectedSwitchIndex = function (self, key, val)
            self._switches[val]:switch(true)
        end,
        allowSwitchOff = function(self, key, val)
            self._allowSwitchOff = val
            for _, v in ipairs(self._switches) do
                v.allowSwitchOff = val
            end
        end
    }
}
function SwitchGroup:ctor()
    self._switches = {}
end

function SwitchGroup:addSwitch(switch)
    table.insert(self._switches, switch)
    if not self.allowMultiSelect then
        switch:onSwitchOn(self._onSwitchOn, self)
    end
    switch.switchIndex = #self._switches
end

function SwitchGroup:_onSwitchOn(switch)
    if not self.allowMultiSelect then
        self:_updateSingleSelect(switch)
    end
end

function SwitchGroup:_updateSingleSelect(switch)
    self._selectedSwitchIndex = switch.switchIndex
    self:emit(SwitchGroupEvent.Selected, switch.switchIndex)
    for _, v in ipairs(self._switches) do
        if v ~= switch then
            v:switch(false)
        end
    end
end

function SwitchGroup:deleteSwitch(switch)
    switch:off(self._onSwitchOn, self)
end

function Node.SwitchGroup()
    
end